//
//  EditAboutViewController.m
//  QT
//
//  Created by 甘世清 on 2025/1/8.
//

#import "EditAboutViewController.h"

@interface EditAboutViewController ()
@property (nonatomic , strong) UILabel * number;
@property (nonatomic , strong) FSTextView * fsTextView;
@end

@implementation EditAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"自我介绍");
    WS(weakSelf);
    [self zx_setRightBtnWithText:SQNSLocalString(@"提交") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
        [weakSelf SQ_Tijiao];
    }];
}

- (void)SQ_UIViewForSelfView{
    UIView * bgView = [[UIView alloc]init];
    bgView .backgroundColor = SQColorF1F1F1;
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 20;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SCREEN_WIDETH-30);
        make.top.equalTo(self.zx_navBar.mas_bottom).offset(20);
        make.centerX.equalTo(self.view);
        make.height.mas_equalTo(200);
    }];
    [bgView addSubview:self.fsTextView];
    [self.fsTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bgView).insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    self.number = [[UILabel alloc]init];
    self.number.textColor =  SQColor999999;
    self.number.font = FONT_MEDIUM(12);
    [self.view addSubview:self.number];
    [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgView.mas_right).offset(-10);
        make.bottom.equalTo(bgView.mas_bottom).offset(-10);
    }];
    self.number.text = @"(0/200)";
    WS(weakSelf);
    [self.fsTextView addTextDidChangeHandler:^(FSTextView *textView) {
        weakSelf.number.text = [NSString stringWithFormat:@"%lu/200",(unsigned long)textView.text.length];
        weakSelf.number.keywords = [NSString stringWithFormat:@"%lu/",(unsigned long)textView.text.length];;
        weakSelf.number.keywordsColor = UIColor.whiteColor;
        [weakSelf.number getLableSizeWithMaxWidth:200];
    }];
    self.fsTextView.text = [UserModel share].remark;
 
}

-(void)SQ_Tijiao{
    if (![self.fsTextView .formatText isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"简介不能为空")];
        return;
    }
    WS(weakSelf);
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.fsTextView.formatText forKey:@"remark"];
    [HttpTool post:@"user/config" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        UserModel  * model = [UserModel share];
        model.remark = self.fsTextView.formatText;
        [UserModel updateLocalUserModel:model];
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"修改成功")];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf SQ_popViewVC];
        });
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
       [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
 

-(FSTextView*)fsTextView{
    if (!_fsTextView) {
        _fsTextView = [FSTextView textView];
        _fsTextView.font = FONT_MEDIUM(14);
        _fsTextView.textColor = SQColor333333;
        _fsTextView.placeholder =SQNSLocalString(@"简单的做个自我描述吧～");
        _fsTextView.placeholderColor = SQColor999999;
        _fsTextView.backgroundColor = UIColor.clearColor;
        _fsTextView.maxLength = 200;
       
    }
    return _fsTextView;
}

@end
